import Api from '@/services/api.js'

export default {
  data() {
    return {
      activeTimes: {}, // 选中的购买次数
      vipInfo: {},
      list: [],
      accountInfo: [
        '成都神策企业管理咨询有限公司',
        '22892101040020312',
        '中国农业银行四川省分行'
      ]
    }
  },
  onLoad(options) {
    console.log('-------------->', options);
    this.vipInfo = JSON.parse(options.func);
    this.getVipsContent();
  },
  methods: {
    // 获取购买权益内容
    async getVipsContent() {
      const { code, result } = await this.$request({
        url: Api.getVipsContent,
      })
      if (code === 200) {
        this.list = result.filter(i => i.price != 0);
      }
    },
    handleItem(e) {
      const { item } = e.currentTarget.dataset;
      if (this.activeTimes.id != item.id) {
        this.activeTimes = item;
      }else {
        this.activeTimes = {};
      }
    },
    // 微信支付
    async handleWxPay() {
      if (!Object.hasOwnProperty.call(this.activeTimes, 'id')) {
        return uni.showToast({ title: '请选择购买次数', icon: 'none' });
      }
      const ret = await this.$Serv.getPayInfo({ vipId: this.activeTimes.id });
      if (ret) {
        uni.showToast({
          title: '购买成功',
          icon: 'none'
        })
        setTimeout(() =>  {
          uni.navigateBack();
        }, 500)
      }
    },
    handleCopy() {
      uni.setClipboardData({
        data: this.accountInfo.join(','),
        success: () => {
          uni.showToast({ title: '复制成功', icon: 'none' });
        }
      })
    }
  }
}